﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using BCCommon;
using BCDto.OA.TeamWork.TeamWorkCategory;
using BCService.Utils;
using BCService.OA.TeamWork.TeamWorkCategory;
using BlackCoffeeRESTful.Configs;

namespace BlackCoffeeRESTful.Controllers.Management.OA.TeamWork
{
    /// <summary>
    /// 协同办公分类
    /// </summary>
    [ApiExplorerSettings(GroupName = "OAAdmin")]
    [Route("api/v1/sim/[controller]")]
    public class TeamWorkCategoryController : ManagementBaseController
    {
        private readonly ITeamWorkCategoryService teamWorkCategoryService;

        public TeamWorkCategoryController(ITeamWorkCategoryService teamWorkCategoryService)
        {
            this.teamWorkCategoryService = teamWorkCategoryService;
        }

        #region 添加协同办公分类
        /// <summary>
        ///  添加协同办公分类
        /// </summary>
        /// <param name="requestDto">协同办公分类信息</param>
        /// <response code="201">添加协同办公分类成功</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加协同办公分类")]
        [ProducesResponseType(typeof(TeamWorkCategoryDto), 201)]
        public IActionResult Post([FromBody] TeamWorkCategoryRequestDto requestDto)
        {
            var result = this.teamWorkCategoryService.Add(requestDto);
            return this.Created(string.Format("api/v1/sim/TeamWorkCategory/{0}", result.TeamWorkCategoryId), result);
        }
        #endregion

        #region 修改协同办公分类
        /// <summary>
        ///  修改协同办公分类
        /// </summary>
        /// <param name="teamWorkCategoryId">协同办公分类Id</param>
        /// <param name="requestDto">协同办公分类信息</param>
        /// <response code="200">修改协同办公分类成功</response>
        /// <returns></returns>
        [HttpPut("{team_work_category_id}")]
        [Log("修改协同办公分类")]
        [ProducesResponseType(typeof(TeamWorkCategoryDto), 200)]
        public IActionResult Put([FromRoute(Name = "team_work_category_id")] int teamWorkCategoryId, [FromBody] TeamWorkCategoryRequestDto requestDto)
        {
            return this.Ok(this.teamWorkCategoryService.Update(teamWorkCategoryId, requestDto));
        }
        #endregion

        #region 删除协同办公分类
        /// <summary>
        ///  删除协同办公分类
        /// </summary>
        /// <param name="teamWorkCategoryId">协同办公分类Id</param>
        /// <response code="204">删除协同办公分类成功</response>
        /// <returns></returns>
        [HttpDelete("{team_work_category_id}")]
        [Log("删除协同办公分类")]
        public IActionResult Delete([FromRoute(Name = "team_work_category_id")] int teamWorkCategoryId)
        {
            this.teamWorkCategoryService.Delete(teamWorkCategoryId);
            return this.NoContent();
        }
        #endregion

        #region 获取协同办公分类
        /// <summary>
        ///  获取协同办公分类
        /// </summary>
        /// <param name="teamWorkCategoryId">协同办公分类Id</param>
        /// <response code="200">获取协同办公分类</response>
        /// <returns></returns>
        [HttpGet("{team_work_category_id}")]
        [ProducesResponseType(typeof(TeamWorkCategoryDto), 200)]
        public IActionResult Get([FromRoute(Name = "team_work_category_id")] int teamWorkCategoryId)
        {
            return this.Ok(this.teamWorkCategoryService.GetEntity(teamWorkCategoryId));
        }
        #endregion

        #region 获取协同办公分类列表
        /// <summary>
        ///  获取协同办公分类列表
        /// </summary>
        /// <response code="200">获取协同办公分类列表</response>
        /// <returns></returns>
        [HttpGet]
        [ProducesResponseType(typeof(IEnumerable<TeamWorkCategoryDto>), 200)]
        public IActionResult Get()
        {
            return this.Ok(this.teamWorkCategoryService.GetList());
        }
        #endregion

        #region 获取协同办公分类（分页）
        /// <summary>
        ///  获取协同办公分类（分页）
        /// </summary>
        /// <param name="teamWorkCategoryName">协同办公分类名称</param>
        /// <param name="teamWorkCategoryCode">协同办公分类编码</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="pageIndex">以 1 起始的页码 (默认 1)。</param>
        /// <param name="pageSize">每页要显示的行数 (默认 10)。</param>
        /// <response code="200">获取协同办公分类（分页）</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<TeamWorkCategoryDto>), 200)]
        public IActionResult Query([FromQuery(Name = "team_work_category_name")] string teamWorkCategoryName,
            [FromQuery(Name = "team_work_category_code")] string teamWorkCategoryCode,
            [FromQuery(Name = "start")] DateTime? start,
            [FromQuery(Name = "end")] DateTime? end,
            int pageIndex = 1,
            int pageSize = 10)
        {
            return this.Ok(this.teamWorkCategoryService.Query(teamWorkCategoryName, teamWorkCategoryCode, start, end, pageIndex, pageSize));
        }
        #endregion

    }
}
